{extend name="platform/base" /}
{block name="resources"/}
<style type="text/css">
    .required{
        color:red;margin-right:10px;
    }
    .error{
        font-size: 12px;
        line-height: 16px;
        color: red;
        margin-top: 10px;
        display:none;
    }


    /* 上传附件样式 */
    .upload-btn-common {
        position: relative;
    }
    .upload-btn-common>div {
        position: absolute;
        cursor: pointer;
        z-index: 2;
        width: 44px;
        margin-left: 250px;
    }
    .upload-btn-common>div .input-file {
        opacity: 0;
        cursor: pointer;
        width: 100%;
        overflow: hidden;
    }
    .upload-btn-common>em {
        font-style: normal;
        background: #999;
        color: #fff;
        position: absolute;
        padding: 0 10px;
        z-index: 1;
        left: 250px;
        height: 30px;
        line-height: 30px;
    }
    .input-common{
        border-radius: 0 !important;
        margin: 0 !important;
        border: 1px solid #D6D6D6 !important;
        box-shadow: none !important;
        font-size: 12px !important;
        width: 250px !important;
        padding: 0 6px !important;
        height: 30px !important;
        box-sizing: border-box;
        resize: none !important;
    }
</style>
{/block}
{block name="main"}
<section class="panel panel-default">
    <header class="panel-heading font-bold"> 添加亲友卡</header>
    <div class="panel-body">
        <form class="form-horizontal" id="form" name="form" onsubmit="">
            <div class="form-group">
                <label class="col-sm-2 control-label"><span class="required">*</span>主题名称</label>
                <div class="col-md-6">
                    <input type="text" class="form-control" id="theme" value="<?php echo $list['theme']; ?>">
                </div>
                <p class="error">请输入亲友卡名称</p>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label"><span class="required">*</span>亲友卡名称</label>
                <div class="col-md-6">
                    <input type="text" class="form-control" id="title" value="<?php echo $list['name']; ?>">
                </div>
                <p class="error">请输入亲友卡名称</p>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label"><span class="required">*</span>亲友卡价格</label>
                <div class="col-md-6">
                    <input type="number" class="form-control" id="price" value="<?php echo $list['price']; ?>">
                </div>
                <p class="error">亲友卡价格</p>
            </div>

            <input type="hidden" id="id" value="<?php echo $list['id']; ?>">
            <div class="line line-dashed line-lg pull-in"></div>
            <!-- 上传图片 -->
            <div class="form-group">
                <label class="col-sm-2 control-label">亲友卡的背景</label>
                <div class="col-sm-2">
                    <p class="imglogo-box"><img id="preview_logo" src="<?php echo $list['background']; ?>" value = "<?php echo $list['background']; ?>" class="imglogo"/></p>
                    <a href="javascript:void(0);" style="display:block;position:relative;z-index:1;">
	              	<span style="width: 97px;height: 34px;position: absolute;left: 0;top: 0;z-index: 2;cursor: pointer;">
	            	<input hidefocus="true" size="1" class="input-file" name="file_upload" id="uploadimg" nc_type="change_store_label" type="file" style="width: 97px;height: 34px;padding: 0;margin: 0;border: none 0;opacity: 0;filter: alpha(opacity = 0);cursor: pointer;"	onchange="imgUpload(this);">
					<input type="hidden" id="logo" value="" />
					</span>
                        <a class="btn btn-default"><i class="fa fa-cloud-upload text"></i><span class="text">上传图片</span></a>
                    </a>
                </div>
            </div>




            <div class="line line-dashed line-lg pull-in"></div>
            <div class="form-group">
                <label class="col-sm-2 control-label">亲友卡的内容</label>
                <div class="col-md-4">
                    <script id="editor" type="text/plain" style="height: 400px;width:750px;"><?php echo $list['card_details']; ?></script>
                    <p class="error"></p>
                        </div>
                        </div>



                        </div>
                        <div class="line line-dashed line-lg pull-in"></div>
                        <div class="form-group">
                        <label class="col-sm-2 control-label">是否启用</label>
                        <div class="col-md-4">
                            <?php if($list['is_status'] == 1){?>
                        <label class="radio-label" style="margin-bottom:10px;"><input type="radio" name="commend_flag" value="1"  id="enableYes" checked>开启</label>
                    <label class="radio-label" style="margin-bottom:10px;"><input type="radio" name="commend_flag" value="0"  id="enableNo">关闭</label>
                                <?php }else{ ?>
                    <label class="radio-label" style="margin-bottom:10px;"><input type="radio" name="commend_flag" value="1"  id="enableYes" >开启</label>
                        <label class="radio-label" style="margin-bottom:10px;"><input type="radio" name="commend_flag" value="0"  id="enableNo" checked>关闭</label>
                        <?php }?>
                        </div>
                        </div><div class="line line-dashed line-lg pull-in"></div>

                    <div class="line line-dashed line-lg pull-in"></div>
                        <div class="form-group">
                        <label class="col-sm-2 control-label">卡片类型</label>
                        <div class="col-md-4">
                    <?php if($list['is_classic'] == 1){?>
                    <label class="radio-label" style="margin-bottom:10px;"><input type="radio" name="classic_flag" value="1"  id="enableYes" checked>经典</label>
                        <label class="radio-label" style="margin-bottom:10px;"><input type="radio" name="classic_flag" value="2"  id="enableNo">精选</label>
                        <?php }else{ ?>
                    <label class="radio-label" style="margin-bottom:10px;"><input type="radio" name="classic_flag" value="1"  id="enableYes" >经典</label>
                            <label class="radio-label" style="margin-bottom:10px;"><input type="radio" name="classic_flag" value="2"  id="enableNo" checked>精选</label>
                        <?php }?>
                    </div>
                    </div><div class="line line-dashed line-lg pull-in"></div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">输入次数</label>
                        <div class="col-md-1">
                        <input type="number" min="0" class="form-control" id="comment_count" value="<?php echo $list['frequency']; ?>">
                        </div>
                        </div>

                        <div class="line line-dashed line-lg pull-in"></div>


                        <div class="form-group">
                        <div class="col-sm-4 col-sm-offset-2">
                        <a href="javascript:void(0);" onclick="save(1)" class="btn btn-primary">保存</a>
                        </div>
                        </div>
                        </form>
                        </div>
                        </section>
                    {/block}
                        {block name="script"}
                    <script src="PLATFORM_JS/ajaxFileUpload.js" type="text/javascript"></script>
                    <script src="__STATIC__/js/file_upload.js" type="text/javascript"></script>
                    <script type="text/javascript" charset="utf-8" src="ADMIN_JS/ueditor/ueditor.config.common.js"></script>
                    <script type="text/javascript" charset="utf-8" src="ADMIN_JS/ueditor/ueditor.all.common.js"></script>
                    <!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
                    <!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
                    <script type="text/javascript" charset="utf-8" src="ADMIN_JS/ueditor/zh-cn.js"></script>
                    {include file="platform/openDialog" /}
                    <script type="text/javascript">
                        var ue = UE.getEditor('editor',{
                            toolbars : [
                                [ 'source', // 源代码
                                    'bold', // 加粗
                                    'italic', // 斜体
                                    'underline', // 下划线
                                    'strikethrough', // 删除线
                                    'forecolor', // 字体颜色
                                    'backcolor', // 背景色
                                    'fontfamily', // 字体
                                    'fontsize', // 字号
                                    'paragraph', // 段落格式
                                    'justifyleft', // 居左对齐
                                    'justifycenter', // 居中对齐
                                    'justifyright', // 居右对齐
                                    'superscript', // 上标
                                    'blockquote', // 引用
                                    'selectall', // 全选
                                    'preview', // 预览
                                    'removeformat', // 清除格式
                                    'inserttable', // 插入表格
                                    'unlink', // 取消链接
                                    'insertrow', // 前插入行
                                    'insertcol', // 前插入列
                                    'mergeright', // 右合并单元格
                                    'mergedown', // 下合并单元格
                                    'deleterow', // 删除行
                                    'deletecol', // 删除列
                                    'splittorows', // 拆分成行
                                    'splittocols', // 拆分成列
                                    'splittocells', // 完全拆分单元格
                                    'deletecaption', // 删除表格标题
                                    'inserttitle', // 插入标题
                                    'mergecells', // 合并多个单元格
                                    'deletetable', // 删除表格
                                    'cleardoc', // 清空文档
                                    'insertimage', // 多图上传
                                    'link', // 超链接
                                    'emotion', // 表情
                                    'insertorderedlist', // 有序列表
                                    'insertunorderedlist', // 无序列表
                                    'fullscreen', // 全屏
                                    'directionalityltr', // 从左向右输入
                                    'directionalityrtl', // 从右向左输入
                                    'imagenone', // 默认
                                    'imageleft', // 左浮动
                                    'imageright', // 右浮动
                                    // 'attachment', // 附件
                                    'imagecenter', // 居中
                                    'lineheight', // 行间距
                                    'customstyle', // 自定义标题
                                ]]
                        });

                        $(function(){
                            UE.getEditor('editor').addListener( 'ready', function() {
                                if($("#content").val()){
                                    UE.getEditor('editor').setContent($("#content").val());
                                }
                            } );
                        })
                        var flag = false;//防止重复提交
                        function save(type){
                            var classic_flag=$("input[name='classic_flag']:checked").val();
                            var commend_flag=$("input[name='commend_flag']:checked").val();

                            var theme=$("#theme").val();
                            var title=$("#title").val();
                            var price=$("#price").val();
                            var id=$("#id").val();
                            var summary=$("#summary").val();
                            var content = UE.getEditor('editor').getContent();
                            if(content.length>30000){
                                showTip("文章内容太长","warning");
                                return;
                            }
                            var image=$("#preview_logo").attr('src');
                            var keyword=$("#keyword").val();
                            var article_id_array=$("#article_id_array").val();
                            var click=$("#click").val();
                            var sort=$("#sort").val();
                            var tag=$("#tag").val();
                            var comment_count=$("#comment_count").val();
                            var share_count=$("#share_count").val();
                            var attachment_path='';

                            var attachment_path = $("#attachment").val();

                            $.ajax({
                                type:"post",
                                url:"{:__URL('PLATFORM_MAIN/FamilyCard/editFamilyCard&id=')}"+id,
                                data:{
                                    // 'class_id':class_id,
                                    // 'short_title':short_title,
                                    // 'source':source,
                                    // 'url':url,
                                    // 'author':author,
                                    // 'summary':summary,
                                    'theme':theme,
                                    'classic_flag':classic_flag,
                                    'price':price,
                                    'title':title,
                                    'image':image,
                                    'content':content,
                                    'commend_flag':commend_flag,
                                    'comment_count':comment_count,
                                },
                                async : true,
                                success:function(data){
                                    //alert(JSON.stringify(data));
                                    showMessage('success', data["message"]);
                                    if(type==1){
                                        location.href = "{:__URL('PLATFORM_MAIN/FamilyCard/index')}";
                                    }
                                }

                            });

                        }
                        /**
                         *模块输入信息验证
                         */
                        function verify(title,class_id){
                            if(title==''){
                                $("#title").parent().next(".error").show();
                                $("#title").focus();
                                return false;
                            }else{
                                $(".error").hide();
                            }
                            if(class_id==0){
                                $("#class_id").parent().next(".error").show();
                                $("#class_id").focus();
                                return false;
                            }else{
                                $(".error").hide();
                            }
                            return true;
                        }

                        //上传方法
                        function imgUpload(event) {
                            var fileid = $(event).attr("id");
                            var data = new Object();
                            var id = $(event).next().attr("id");
                            var only_type = $(event).attr('only-type');
                            if(!only_type){
                                data.file_path = UPLOADCOMMON;
                            }else{
                                data.file_path = UPLOADFILE;
                            }
                            uploadFile(fileid,data,function(res){

                                if(res.code){
                                    $("#" + id).val(res.data);
                                    $("#text_" + id).val(res.data);
                                    $("#preview_"+ id).attr("src",__IMG(res.data));
                                    showTip(res.message,"success");
                                }else{
                                    showTip(res.message,"error");
                                }
                            });
                        }

                        /**
                         * 删除文件
                         * @param {Object} file_url
                         * @param {Object} even
                         */
                        function delete_file(file_url,even){
                            $.ajax({
                                type:"post",
                                url:"{:__URL('ADMIN_MAIN/system/delete_file')}",
                                data:{'file_url':file_url},
                                dataType:'json',
                                success:function(data){
                                    if (data['code']>0) {
                                        $( "#dialog" ).dialog({
                                            buttons: {
                                                "确定,#01B044": function() {
                                                    $(this).dialog('close');
                                                }
                                            },
                                            contentText:"附件移除成功",
                                            time:1,
                                        });
                                        $(even).parent().empty();
                                    }else{
                                        $( "#dialog" ).dialog({
                                            buttons: {
                                                "确定,#0059d6,#fff": function() {
                                                    $(this).dialog('close');
                                                }
                                            },
                                            contentText:data['message'],
                                        });
                                    }
                                }
                            });
                        }

                    </script>

                    {/block}